require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
if(!userInfo){
    location.href="/loginIndex"
}
var vm = new Vue({
    el:"#addName",
    data:{
        pop:{
            question: "确定要跳过此步骤？",
            show: false
        },
        uInfo:userInfo,
        loginUid:userInfo.id,
        headImg:"",
        name:"",
        results:""
    },
    mounted:function(){
        // this.searchObject = this.getQueryStringArgs();
        // this.recruitId=this.searchObject&&this.searchObject.recruitId;
        // this.getRecruitById();
    },
    methods:{
        //后退
        getBack:function(){
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        getChange:function(){
            var that=this;
            that.headImg=$("#fileinput").get(0).files[0];
            lrz(that.headImg, function (results) {
                // 你需要的数据都在这里，可以以字符串的形式传送base64给服务端转存为图片。
                console.log(results);
                that.results=results;
            });

        },
        //完善信息
        setSecondInfo:function(){
            var that=this;
            if(!that.headImg){
                vm.$refs.prompt.toast("请选择头像！");
                return false;
            }
            if(!that.name){
                vm.$refs.prompt.toast("请填写昵称！");
                return false;
            }else{
                that.name=Trim(that.name);
            }
            console.log(that.name);
            var formData = new FormData();
            formData.append("loginUid", that.loginUid);
            formData.append("headImg",that.headImg);
            formData.append("name", that.name);
            $.ajax({
                url:host+'/v1/user/setSecondInfo',
                type:'POST',
                data:formData,
                dataType:'json',
                async: false,
                cache: false,
                contentType: false, //不设置内容类型
                processData: false, //不处理数据
                success:function(data){
                    console.log(data);
                    // alert(data.msg);
                    if(data.code==0){
                        userInfo.name=that.name;
                        userInfo.headImg=data.data;
                        sessionStorage.setItem("userInfo",JSON.stringify(userInfo));
                        that.getNext();
                    }
                },
                error:function(){
                    vm.$refs.prompt.toast("操作失败！")
                }
            });
        },
        //退货显示框
        getIsClassify:function(){
            this.pop.show=!this.pop.show;
        },
        getNext:function(){
            location.href="/user/myLable";
        }
    },
    watch:{

    }
});
//去掉所有空格
function Trim(str) {
    var result;
    result = str.replace(/\s+/g," ");
    // if(is_global==1){
    //     result = result.replace(/\s/g,"");
    // }
    return result.replace(/(^\s*)|(\s*$)/g,"");
}